﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using XbsWebAPI.Application;
using XbsWebAPI.Application.QueryModel;
using XbsWebAPI.EntityFrameworkCore.Entities;

namespace XbsWebAPI.MainHost.Controllers
{
    /// <summary>
    /// 营位管理
    /// </summary>
    [ApiController]
    [Route("api/xbs_v1/[controller]")]
    public class CampController : Controller
    {
        private readonly ICampAppService _campAppService;

        public CampController(ICampAppService campAppService)
        {
            _campAppService = campAppService;
        }

        /// <summary>
        /// 新建营位
        /// </summary>
        /// <param name="model">营位入参</param>
        /// <returns></returns>
        [HttpPost,Route("[action]")]
        public async Task<ResultDto<string>> AddCamp(CreateCampDto model)
        {
            var result = await _campAppService.CreateCampAsync(model);
            return result;
        }

        /// <summary>
        /// 编辑营位
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("[action]")]
        public async Task<ResultDto<string>> EditCamp(EditCampDto model)
        {
            var result = await _campAppService.EditCampAsync(model);

            return result;
                
         }

        /// <summary>
        /// 根据Id查询营位
        /// </summary>
        /// <param name="id">营位Id</param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ResultDto<GetCampDto> FindCamp(Guid id)
        {
            var camp = _campAppService.GetCampById(id);

            return camp;
        }

        /// <summary>
        /// 下拉框 展示营位列表
        /// </summary>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ResultDto<List<SelectCampDto>> FindSelectCamps()
        {
            return _campAppService.GetSelectCamps();
        }

        /// <summary>
        /// 分页查询营位
        /// </summary>
        /// <param name="name">营位名称</param>
        /// <param name="pageNumber">第几页，默认1</param>
        /// <param name="pageSize">每页多少条，默认10</param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ResultDto<PageListDto<ListCampDto>> FindCampPagedList(string name,int? pageNumber,int? pageSize)
        {
            QueryCamp query = new QueryCamp
            {
                Name = name,
                PageNumber = pageNumber,
                PageSize = pageSize
            };
            var result = _campAppService.GetPagedList(query);

            return result;
        }

        /// <summary>
        /// 删除营位
        /// </summary>
        /// <param name="id">营位Id</param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public async Task<ResultDto<string>> DeleteCamp(Guid id)
        {
            var result = await _campAppService.RemoveCampAsync(id);

            return result;
        }

    }
}
